/**
 * Created by ZT on 2018/4/27 0027.
 */
/*
* 该方法用于系统登录验证
* */
$(function () {
    Vue.prototype.formatterLang= function (value) {
        return initString(value);
    };
    var loginEl =new Vue({
        el:'#loginVue',
        data:{
            user:{
                username:'',
                passwd:''
            }
        },
        mounted:function () {

        },
        methods:{
            submitLogin:function () {
                var target = this;
                var $form = $('#formLogin');
                var result = validateForm($form);/*验证方法，出现提示*/
                var formData = this.user;
                formData.passwd = md5(formData.passwd);
                var url='auths/login';
                 loginKey = false;
                this.fetch({
                        url : url,
                    method  : 'post',
                     params : target.user
                }).then(function (response) {
                    console.log(response);
                    target.saveToken(response.data['access_token']);
                   window.location.href=' / ';
                });
            },
            saveToken:function (token) {
                var d = new Date();
                d.setTime(d.getTime() + (365 * 24 * 60 * 60 * 1000));
                var expires = "expires=" + d.toUTCString();
                document.cookie ="access_token =" + token + "; " + expires;
            }
        }

    });
});